<template>
	<view class="good-item-page">
		<!-- 商品左侧图片区域 -->
		<view class="good-item-left">
			<radio :checked="item.goods_state" class="goods-radio" color="#C00000" v-if="showRadio" @click="radioChange"></radio>
			<image :src="item.goods_small_logo || defaultPic"></image>
		</view>
		<!-- 商品右侧信息区域 -->
		<view class="good-item-right">
			<!-- 标题 -->
			<view class="good-item-title">
				{{item.goods_name}}
			</view>
			<view class="good-item-box">
				<!-- 价格 -->
				<view class="good-item-price">￥{{item.goods_count?(item.goods_price * item.goods_count).toFixed(2):item.goods_price.toFixed(2)}}</view>
				<!-- 商品数量 -->
				<uni-number-box :value="item.goods_count" @change="checkedNum" :min="1" v-if="showNum" />
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		props:{
			item:{
				type:Object,
				default: {}
			},
			// 是否展示图片左侧的 radio
			showRadio: {
			  type: Boolean,
			  // 如果外界没有指定 show-radio 属性的值，则默认不展示 radio 组件
			  default: false,
			},
			//是否展示商品的数量
			showNum: {
				type: Boolean,
				default: false
			}
		},
		name:"my-goods",
		data() {
			return {
				// 默认的空图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
				isChecked: false
			};
		},
		methods:{
			radioChange(){
				// console.log(ref)
				this.$emit('radio-change',{
					//商品id
					goods_id:this.item.goods_id,
					//商品选中状态 默认为true点击后需要为false所以需要取反
					goods_state:!this.item.goods_state
				})
			},
			checkedNum(ref){
				this.$emit('num-change',{
					//商品id
					goods_id:this.item.goods_id,
					//商品数量
					goods_num:ref
				})
			}
		}
	}
</script>

<style lang="scss">
.good-item-page{

	display: flex;
	border-bottom: 3px solid #efefef;
	background-color: white;
	padding: 5px 5px;
	// <!-- 商品左侧图片区域 -->
	.good-item-left{
		display: flex;
		justify-content: space-between;
		align-items: center;
		//选中按钮
		.goods-radio{
			color: red;
		}
		
		image{
			width: 100px;
			height: 100px;	
		}
	}
	// <!-- 商品右侧图片区域 -->
	.good-item-right{
		//标题
		margin: 5px 10px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.good-item-title{
			font-size: 13px;
		}
		.good-item-box{
			margin-top: 20px;
			display: flex;
			justify-content: space-between;
			//价格
			.good-item-price{
				color: red;
			}
		}
	}
}
</style>